package com.atguigu.redis;

import com.atguigu.constant.RedisConst;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;


@Configuration
public class RedisChannelConfig {

//用哪个类的哪个方法处理到接收的消息
        @Bean
            public static MessageListenerAdapter messageListenerAdapter(RedisMessageReceiver redisMessageReceiver){
            return new MessageListenerAdapter(redisMessageReceiver,"receiceChannelMessage");
        }

    @Bean
    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, MessageListenerAdapter messageListenerAdapter){
        RedisMessageListenerContainer container=new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        //订阅哪个主题
        container.addMessageListener(messageListenerAdapter, new PatternTopic(RedisConst.PREPARE_PUB_SUB_SECKILL));
    return container;
        }





}
